package com.tedu.controller;

import com.sun.org.apache.regexp.internal.RE;
import com.tedu.sp01.pojo.Item;
import com.tedu.sp01.pojo.Order;
import com.tedu.sp01.pojo.User;
import com.tedu.web.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class RibbonController {
@Autowired
    private RestTemplate restTemplate;
@GetMapping("/item-service/{orderId}")
    public JsonResult<List<Item>>  getItems(@PathVariable String orderId){
    return  restTemplate.getForObject(
            "http://item-service/{1}",
            JsonResult.class,
            orderId);
}
@PostMapping("/item-service/decreaseNumber")
    public  JsonResult<?>  decreaseNumber(@RequestBody  List<Item> items){
return   restTemplate.postForObject("http://item-service/decreaseNumber",
        items,
        JsonResult.class);
}
@GetMapping("/user-service/{userId}")
public  JsonResult<User> getUser(@PathVariable Integer userId){
    return restTemplate.getForObject("http://user-service/{1}",
            JsonResult.class,
            userId);
}
@GetMapping("/user-service/{userId}/score")
    public JsonResult getScore(@PathVariable Integer userId, Integer score){
    return restTemplate.getForObject("http://user-service/{1}/score?score={2}",
            JsonResult.class, userId, score);
}
@GetMapping("/order-service/{orderId}")
public JsonResult<Order> getOrder(@PathVariable String orderId) {
    return restTemplate.getForObject("http://order-service/{1}",
            JsonResult.class, orderId);

}
@GetMapping("/order-service/")
public JsonResult addOrder() {
    return restTemplate.getForObject("http://order-service/", JsonResult.class);
}


}
